<template>
  <PageContainer :transparent="false">
    <BaseHeader v-model:headerHeight="headerHeight" />
    <view class="hb-relative">
      <TopButton :header-height="headerHeight" />
      <view class="hb-m-4">
        <!-- 用户信息 -->
        <!-- <view class="hb-mb-4 hb-flex hb-items-center hb-h-14">
        <view class="hb-flex-1 hb-flex hb-items-center hb-h-full">
          <TmImage
            class="hb-flex-shrink-0"
            src="https://s3-alpha-sig.figma.com/img/7478/6c21/e408e33c1b87435ea23118257a5c4b13?Expires=1741564800&Key-Pair-Id=APKAQ4GOSFWCW27IBOMQ&Signature=NxQC8-nhqcc4GmcuW-oN7DPhRuswQpNGtMOWVPGGbzWMcGETrGSlgGLYDq6rM8NgCXr6u4YP-zu0Vml8OP5FHgTtVl63t5TLfddwq24~8~M8sxw-s8gzt29aMTQ7olQTEae8cmVuWNHhDuS~mD3oIowcLbdEqOGL5SfXtjIwwvoFUNZ9i~jAEcK2tig~9NZteMCQh6jKdraCj~NI3YTlIUnh9D6WoxXkDmE1cG325ta8aS2890loNYgGt7nKJwj4dhmG~~xswygoxHHxzVVCogyYAp2AZihO4FK1d0KXktqM91CMfARWfZdUlUCrBEXKu7~JJpOSHEPFYXyoY11jZw__"
            :round="25"
            :width="96"
            :height="96"
          />

          <view class="hb-flex-1 hb-h-full hb-ml-2 hb-flex hb-flex-col hb-justify-between">
            <TmText _class="hb-font-bold" :label="userInfo?.userName || '用户名'" :font-size="36" />
            <TmTag
              :margin="[0, 0]"
              label="未实名"
              :follow-theme="false"
              :round="1"
              :font-size="24"
              color="#D0F7FF"
              font-color="#2878FF"
            />
          </view>
        </view>
        <TmIcon name="tmicon-qrcode" :font-size="80" :line-height="0" />
      </view> -->
        <!-- 操作列表 -->
        <view
          class="hb-box-shadow-base hb-mb-3 hb-pb-3 hb-bg-white hb-overflow-hidden hb-rounded-xl"
        >
          <TmCell
            _class="hb-font-bold"
            :padding="[40, 40, 40, 24]"
            :margin="[0, 0]"
            :round="6"
            :titleFontSize="28"
            :transparent="true"
            :right-text="auditStatusText(userInfo?.aiBotCertificationVo?.auditStatus).text"
            title="实名认证"
            @click="handleRealNameAuth"
          />
          <view
            v-if="userInfo?.aiBotCertificationVo === null"
            class="hb-bg-[#EBEDF0] hb-h-30 hb-p-4 hb-mx-5 hb-rounded-lg hb-flex hb-flex-col hb-items-center hb-justify-between"
          >
            <TmText
              label="实名认证后可添加好友，加入/创建圈子等，获得更多合作机会"
              _class="hb-text-center"
              :font-size="28"
            />
            <TmButton
              :round="11"
              label="开始认证"
              :margin="[0, 0]"
              :font-size="28"
              :height="64"
              @click="handleRealNameAuth"
            />
          </view>
        </view>
        <view class="hb-box-shadow-base hb-mb-3 hb-bg-white hb-overflow-hidden hb-rounded-xl">
          <TmCell
            _class="hb-font-bold"
            :padding="[40]"
            :margin="[0, 0]"
            :round="6"
            :titleFontSize="28"
            :transparent="true"
            title="数据统计"
            @click="handleDataStatistics"
          />
        </view>
        <view class="hb-box-shadow-base hb-mb-3 hb-bg-white hb-overflow-hidden hb-rounded-xl">
          <TmCell
            _class="hb-font-bold"
            :padding="[40]"
            :margin="[0, 0]"
            :round="6"
            :titleFontSize="28"
            :transparent="true"
            title="管理员设置"
            @click="handleAssistantManage"
          />
        </view>
        <view class="hb-box-shadow-base hb-mb-3 hb-bg-white hb-overflow-hidden hb-rounded-xl">
          <TmCell
            _class="hb-font-bold"
            :padding="[40]"
            :margin="[0, 0]"
            :round="6"
            :titleFontSize="28"
            :transparent="true"
            title="高级设置"
            @click="handleAiAdvancedSettings"
          />
        </view>
        <view class="hb-box-shadow-base hb-mb-8 hb-bg-white hb-overflow-hidden hb-rounded-xl">
          <TmCell
            _class="hb-font-bold"
            :padding="[40]"
            :margin="[0, 0]"
            :round="6"
            :titleFontSize="28"
            :transparent="true"
            title="客服中心"
            @click="handleCustomerService"
          />
        </view>
        <tm-action-menu
          :round="10"
          :list="certificationTypeList"
          v-model:model-value="showAuthTypeMenu"
          v-model:active="selectedAuthType"
          @cancel="showAuthTypeMenu = false"
          @change="handleAuthTypeChange"
          title="请选择认证方式"
          cancelText="取消"
          :hideCancel="false"
        />
        <!-- 切换账号 -->
        <TmButton
          label="切换账号"
          :block="true"
          :round="11"
          :height="88"
          @click="handleSwitchAccount"
        />
      </view>
    </view>
    <Tabbar path="mine" />
  </PageContainer>
</template>

<script lang="ts" setup>
  /* mine 我的 */
  import { useUserStore } from '@/store/modules/user';
  import Tabbar from '../components/Tabbar.vue';
  import BaseHeader from '../components/BaseHeader.vue';
  import TopButton from '../components/TopButton.vue';
  import { isCreatedAI } from '@/utils/is';
  import { auditStatusText, AuthTypeEnum, authTypeText } from '@/enums/LoginEnum';

  const userStroe = useUserStore();
  const { userInfo } = storeToRefs(userStroe);
  const headerHeight = ref(44);

  uni.hideShareMenu({
    hideShareItems: ['shareAppMessage', 'shareTimeline'],
  });

  const handleSwitchAccount = () => {
    navigateTo({
      name: 'login',
      options: {},
    });
  };

  const handleDataStatistics = () => {
    isCreatedAI(() =>
      navigateTo({
        name: 'dataStatistics',
      }),
    );
  };

  const handleAssistantManage = () => {
    isCreatedAI(() =>
      navigateTo({
        name: 'assistantManage',
      }),
    );
  };

  const handleAiAdvancedSettings = () => {
    isCreatedAI(() =>
      navigateTo({
        name: 'aiAdvancedSettings',
      }),
    );
  };

  // 认证类型列表
  const certificationTypeList = [
    { ...authTypeText(AuthTypeEnum.PERSONAL) },
    {
      ...authTypeText(AuthTypeEnum.ENTERPRISE),
    },
    {
      ...authTypeText(AuthTypeEnum.ORGANIZATION),
    },
  ];
  const showAuthTypeMenu = ref(false);
  const selectedAuthType = ref(undefined);
  const handleAuthTypeChange = (item: any) => {
    navigateTo({
      name: 'realNameAuth',
      options: {
        authType: item.type,
      },
    });
  };
  const handleRealNameAuth = () => {
    isCreatedAI(() => {
      if (userInfo.value?.aiBotCertificationVo?.auditStatus === undefined) {
        showAuthTypeMenu.value = true;
        return;
      }
      navigateTo({
        name: 'realNameAuthResult',
      });
    });
  };

  const handleCustomerService = () => {
    navigateTo({
      name: 'aiChatPage',
      options: {
        uuid: userStroe.customerServiceUuid,
      },
    });
  };

  onShareAppMessage(() => ({}));
  onPageScroll(() => {});
</script>
